﻿
using Newtonsoft.Json;
using RTW.OA.Areas.System.Servers;
using RTW.OA.Models;
using RTW.Utils.Utils;
using System;
using System.Collections.Generic;
using System.Web.Mvc;

namespace RTW.OA.Areas.System.Controllers
{
    public class SealLogController : Controller
    {
	      private SealLogServers seallogServers;

		    public SealLogController()
			{
				seallogServers = new SealLogServers();
			}


		// GET: System/SealLog
        public ActionResult Index()
        {
		      		
           return View();
        }

		// GET: System/SealLog/Edit/5
        public ActionResult Edit(int? id)
        {
				                  var model = new seal_log();
            if (id != null)
            {
                ViewBag.Title = "编辑电子印章使用记录表";
                model = GetModel(id.Value.ToString());
            }
            else
            {
                ViewBag.Title = "新建电子印章使用记录表";
            }
            return View(model);
        }

		// POST: System/SealLog/Edit/5
        [HttpPost]
        public ActionResult Edit(int? id, seal_log model)
        {
			            try
            {
                if (id != null )
                {
				    seallogServers.Update(model);
                    ViewBag.msg = "修改电子印章使用记录表信息成功！";
                }
                else
                {

					seallogServers.Add(model);
                    ViewBag.msg = "新增电子印章使用记录表信息成功！";
                    model = new seal_log();
                }
            }
            catch
            {
                ViewBag.msg = "提交出现错误！";
            }

            return View(model);
        }

		// GET: System/SealLog/Delete/5
        public ActionResult Delete(int id)
        {
		    if (id != 0)
            {
                seallogServers.Del(id.ToString());
                ViewBag.msg = "删除电子印章使用记录表信息成功！";                   
            }    
            return Content("");
        }


		 #region //GetData
		public string GetTableJsonResult()
        {
            var list = seallogServers.GetData();
            return JsonConvert.SerializeObject(list);
        }

		public seal_log GetModel(string id)
        {
            var model = seallogServers.GetModelById(id);
            return model;
        }

		 #endregion //GetData
	}
}